package com.pmt.feedplayer.android

import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.automirrored.filled.List
import androidx.compose.material.icons.filled.Settings
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.Icon
import androidx.compose.material3.NavigationBar
import androidx.compose.material3.NavigationBarItem
import androidx.compose.material3.Scaffold
import androidx.compose.material3.Text
import androidx.compose.material3.TopAppBar
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import com.pmt.feedplayer.ui.VideoListViewModel

/**
 * 主应用导航控制器
 */
@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun AppNavigation(viewModel: VideoListViewModel) {
    // 当前选中的标签页
    var selectedTab by remember { mutableStateOf(0) }
    
    Scaffold(
        bottomBar = {
            if (!viewModel.showPlayer.value) {
                NavigationBar {
                    NavigationBarItem(
                        icon = {
                            Icon(
                                imageVector = Icons.AutoMirrored.Filled.List,
                                contentDescription = "本地视频"
                            )
                        },
                        label = { Text("视频") },
                        selected = selectedTab == 0,
                        onClick = { selectedTab = 0 }
                    )
                    NavigationBarItem(
                        icon = {
                            Icon(
                                imageVector = Icons.AutoMirrored.Filled.List,
                                contentDescription = "音频"
                            )
                        },
                        label = { Text("音频") },
                        selected = selectedTab == 1,
                        onClick = { selectedTab = 1 }
                    )
                    NavigationBarItem(
                        icon = {
                            Icon(
                                imageVector = Icons.Filled.Settings,
                                contentDescription = "设置"
                            )
                        },
                        label = { Text("设置") },
                        selected = selectedTab == 2,
                        onClick = { selectedTab = 2 }
                    )
                }
            }
        },
        topBar = { 
            // 只有在视频标签页且不显示播放器时显示顶部栏
            if (selectedTab == 0 && !viewModel.showPlayer.value) {
                TopAppBar(title = { Text("本地视频") })
            } else if (selectedTab == 1) {
                TopAppBar(title = { Text("提取的音频") })
            } else if (selectedTab == 2) {
                TopAppBar(title = { Text("设置") })
            }
        }
    ) { paddingValues ->
        when (selectedTab) {
            0 -> VideoTabContent(viewModel, paddingValues)
            1 -> AudioTabContent(paddingValues)
            2 -> SettingsTabContent(paddingValues)
        }
    }
}